<?php
use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\MediaWikiServices;
/**
- * @covers LinkRenderer
+ * @covers MediaWiki\Linker\LinkRenderer
*/
class LinkRendererTest extends MediaWikiLangTestCase {
/**
- * @var TitleFormatter
+ * @var LinkRendererFactory
*/
- private $titleFormatter;
+ private $factory;
public function setUp() {
parent::setUp();
'wgScriptPath' => '/w',
'wgScript' => '/w/index.php',
] );
- $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
+ $this->factory = MediaWikiServices::getInstance()->getLinkRendererFactory();
+
}
public function testMergeAttribs() {
$target = new TitleValue( NS_SPECIAL, 'Blankpage' );
- $linkRenderer = new LinkRenderer( $this->titleFormatter );
+ $linkRenderer = $this->factory->create();
$link = $linkRenderer->makeBrokenLink( $target, null, [
// Appended to class
'class' => 'foobar',
public function testMakeKnownLink() {
$target = new TitleValue( NS_MAIN, 'Foobar' );
- $linkRenderer = new LinkRenderer( $this->titleFormatter );
+ $linkRenderer = $this->factory->create();
// Query added
$this->assertEquals(
public function testMakeBrokenLink() {
$target = new TitleValue( NS_MAIN, 'Foobar' );
$special = new TitleValue( NS_SPECIAL, 'Foobar' );
- $linkRenderer = new LinkRenderer( $this->titleFormatter );
+ $linkRenderer = $this->factory->create();
// action=edit&redlink=1 added
$this->assertEquals(
}
public function testMakeLink() {
- $linkRenderer = new LinkRenderer( $this->titleFormatter );
+ $linkRenderer = $this->factory->create();
$foobar = new TitleValue( NS_SPECIAL, 'Foobar' );
$blankpage = new TitleValue( NS_SPECIAL, 'Blankpage' );
$this->assertEquals(
$linkRenderer->makeLink( $foobar, new HtmlArmor( '<script>evil()</script>' ) )
);
}
+
+ public function testGetLinkClasses() {
+ $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
+ $linkCache = new LinkCache( $titleFormatter );
+ $foobarTitle = new TitleValue( NS_MAIN, 'FooBar' );
+ $redirectTitle = new TitleValue( NS_MAIN, 'Redirect' );
+ $userTitle = new TitleValue( NS_USER, 'Someuser' );
+ $linkCache->addGoodLinkObj(
+ 1, // id
+ $foobarTitle,
+ 10, // len
+ 0 // redir
+ );
+ $linkCache->addGoodLinkObj(
+ 2, // id
+ $redirectTitle,
+ 10, // len
+ 1 // redir
+ );
+
+ $linkCache->addGoodLinkObj(
+ 3, // id
+ $userTitle,
+ 10, // len
+ 0 // redir
+ );
+
+ $linkRenderer = new LinkRenderer( $titleFormatter, $linkCache );
+ $linkRenderer->setStubThreshold( 0 );
+ $this->assertEquals(
+ '',
+ $linkRenderer->getLinkClasses( $foobarTitle )
+ );
+
+ $linkRenderer->setStubThreshold( 20 );
+ $this->assertEquals(
+ 'stub',
+ $linkRenderer->getLinkClasses( $foobarTitle )
+ );
+
+ $linkRenderer->setStubThreshold( 0 );
+ $this->assertEquals(
+ 'mw-redirect',
+ $linkRenderer->getLinkClasses( $redirectTitle )
+ );
+
+ $linkRenderer->setStubThreshold( 20 );
+ $this->assertEquals(
+ '',
+ $linkRenderer->getLinkClasses( $userTitle )
+ );
+ }
+
}